From: Eric Huss Date: Sun, 8 Oct 2017 22:23:21 +0000 (-0700) Subject: Fix wrong profile selection for `cargo build` and `cargo rustc`. X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~5^2~22^2~3 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=0acc67ca470b87ec7626fb7d86941a7724307320;p=cargo.git Fix wrong profile selection for `cargo build` and `cargo rustc`. --- diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index d6678ac6b..b646afeb0 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -611,6 +611,16 @@ fn generate_targets<'a>(pkg: &'a Package, let test_profile = if profile.check { &profiles.check_test + } else if mode == CompileMode::Build { + test + } else { + profile + }; + + let bench_profile = if profile.check { + &profiles.check_test + } else if mode == CompileMode::Build { + &profiles.bench } else { profile }; @@ -645,7 +655,7 @@ fn generate_targets<'a>(pkg: &'a Package, targets.append(&mut propose_indicated_targets( pkg, tests, "test", Target::is_test, test_profile)?); targets.append(&mut propose_indicated_targets( - pkg, benches, "bench", Target::is_bench, test_profile)?); + pkg, benches, "bench", Target::is_bench, bench_profile)?); targets } }; diff --git a/tests/build.rs b/tests/build.rs index 5cb3476fe..09411650e 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -3902,3 +3902,59 @@ fn uplift_dsym_of_bin_on_mac() { assert_that(&p.bin("c.dSYM"), is_not(existing_dir())); assert_that(&p.bin("d.dSYM"), is_not(existing_dir())); } + +// Make sure that `cargo build` chooses the correct profile for building +// targets based on filters (assuming --profile is not specified). +#[test] +fn build_filter_infer_profile() { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.1.0" + authors = [] + "#) + .file("src/lib.rs", "") + .file("src/main.rs", "fn main() {}") + .file("tests/t1.rs", "") + .file("benches/b1.rs", "") + .file("examples/ex1.rs", "fn main() {}") + .build(); + + assert_that(p.cargo("build").arg("-v"), + execs().with_status(0) + .with_stderr_contains("\ + [RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \ + --emit=dep-info,link[..]") + .with_stderr_contains("\ + [RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \ + --emit=dep-info,link[..]") + ); + + p.root().join("target").rm_rf(); + assert_that(p.cargo("build").arg("-v").arg("--test=t1"), + execs().with_status(0) + .with_stderr_contains("\ + [RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \ + --emit=dep-info,link[..]") + .with_stderr_contains("\ + [RUNNING] `rustc --crate-name t1 tests[/]t1.rs --emit=dep-info,link[..]") + .with_stderr_contains("\ + [RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \ + --emit=dep-info,link[..]") + ); + + p.root().join("target").rm_rf(); + assert_that(p.cargo("build").arg("-v").arg("--bench=b1"), + execs().with_status(0) + .with_stderr_contains("\ + [RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \ + --emit=dep-info,link[..]") + .with_stderr_contains("\ + [RUNNING] `rustc --crate-name b1 benches[/]b1.rs --emit=dep-info,link \ + -C opt-level=3[..]") + .with_stderr_contains("\ + [RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \ + --emit=dep-info,link[..]") + ); +} diff --git a/tests/check.rs b/tests/check.rs index 2e547bd21..f58348487 100644 --- a/tests/check.rs +++ b/tests/check.rs @@ -478,9 +478,9 @@ fn check_unit_test_profile() { badtext } } - "#); + "#) + .build(); - foo.build(); assert_that(foo.cargo("check"), execs().with_status(0)); assert_that(foo.cargo("check").arg("--profile").arg("test"), @@ -529,9 +529,9 @@ fn check_unit_test_all_tests() { mod tests { fn unused_unit_b1() {} } - "#); + "#) + .build(); - p.build(); assert_that(p.cargo("check"), execs().with_status(0) .with_stderr_contains("[..]unused_normal_lib[..]") @@ -575,8 +575,8 @@ fn check_artifacts() .file("src/main.rs", "fn main() {}") .file("tests/t1.rs", "") .file("examples/ex1.rs", "fn main() {}") - .file("benches/b1.rs", ""); - p.build(); + .file("benches/b1.rs", "") + .build(); assert_that(p.cargo("check"), execs().with_status(0)); assert_that(&p.root().join("target/debug/libfoo.rmeta"), existing_file()); diff --git a/tests/rustc.rs b/tests/rustc.rs index 36bd14e60..da6aced75 100644 --- a/tests/rustc.rs +++ b/tests/rustc.rs @@ -217,7 +217,7 @@ fn build_with_args_to_one_of_multiple_tests() { [RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib --emit=dep-info,link \ -C debuginfo=2 -C metadata=[..] \ --out-dir [..]` -[RUNNING] `rustc --crate-name bar tests[/]bar.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 \ +[RUNNING] `rustc --crate-name bar tests[/]bar.rs --emit=dep-info,link -C debuginfo=2 \ -C debug-assertions [..]--test[..]` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] ", url = p.url())));